home *** CD-ROM | disk | FTP | other *** search
- /*
- KARAOKE
-
- Copyright (c) 1993 94 JP COCATRIX . All rights reserved.
- */
- /* This is the interface module used in karados
- given as an explaination of how the resident code like Ultramid
- is used.
- These primitives are called only if the output mode is s (-po=s)
- I Hope it is self documented.
- If loading a patches is no meaning for you, just ignore in the TSR
- The APP_START and APP_END is only a protection for multiple users
- to avoid the remove of the TSR if a program is still using it.
- The key for detection for an other TSR than ULTRAMID
- is KARADOS. Dont use ULTRAMID
- */
- #include <stdio.h>
- #include <string.h>
- #include <dos.h>
-
- #define TSR_LOAD_PATCH 12
- #define TSR_UNLOAD_ALL_PATCHES 15
- #define TSR_MIDI_OUT 16
- #define TSR_ALL_NOTES_OFF 18
- #define TSR_APP_START 26
- #define TSR_APP_END 27
-
- #define control_change 0xB0
- #define after_touch 0xD0
-
- extern enum HARD {RIEN,SB,GUS,MPU401,COM1,COM2,COM3,COM4} hardware;
- extern void SaySo(char *texte,int multiple);
- extern short inrange(unsigned char,unsigned char min,unsigned char max);
- extern const char *getInstrument(unsigned char);
- void sbFmSound3(int,int,int );
- //*******************************************************************
- // code Synth. output
- //*******************************************************************
-
- void (far *um_hook)(void) = 0L;
-
-
- void um_parameter( int channel, int control, int value )
- {
- sbFmSound3( (control_change+channel),control,value );
- }
-
- void loadpatch( int patch )
- {
- char strg[80];
- if (um_hook)
- {
- if (patch <128)
- sprintf(strg,"Loading %s",getInstrument(patch));
- else
- {
- if (!inrange(patch,128+27,128+87)) return;
- sprintf(strg,"Loading drum %d",patch-128);
- }
- SaySo(strg,6);
- _AX = TSR_LOAD_PATCH;
- _CX = patch;
- (*um_hook)();
- }
- }
-
-
- int reset_um( )
- {
- int i;
-
- _AX = TSR_ALL_NOTES_OFF;
- if (um_hook) (*um_hook)();
- for (i=0; i < 16; i++) {
- um_parameter(i, 0x78, 0); /* all sounds off */
- um_parameter(i, 0x79, 0); /* reset all controllers */
- um_parameter(i, 100, 0); /* RPN MSB 0 */
- um_parameter(i, 101, 0); /* RPN LSB 0 */
- um_parameter(i, 6, 2); /* Pitch Bend Sensitivity MSB */
- um_parameter(i, 38, 0); /* Pitch Bend Sensitivity LSB */
- }
- return(1);
- }
-
- void um_cleanup( void )
- {
- if (um_hook)
- {
- SaySo("Unload Patches",6);
- _AX = TSR_UNLOAD_ALL_PATCHES;
- (*um_hook)();
- reset_um();
- _AX = TSR_APP_END;
- (*um_hook)();
- }
- }
-
-
- //***********************************************************************
- // code commun common code
- //***********************************************************************
- // name with FM are for historical reasons !!
- #pragma warn -par
- int initfm()
- {
- int vector, i;
- char far *stamp;
- switch (hardware)
- {
- case GUS:
- case SB:
- case MPU401:
- case COM1:
- case COM2:
- case COM3:
- case COM4:
- for (vector=0x78; vector <= 0x7f; vector++)
- {
- um_hook = (void (far *)())getvect(vector);
- stamp = (char far *)MK_FP( FP_SEG(um_hook), 0x103 );
- if ((strncmp(stamp, "ULTRAMID", 8) == 0)||(strncmp(stamp, "KARADOS", 7) == 0))
- break;
- stamp = (char far *)MK_FP( FP_SEG(um_hook), FP_OFF(um_hook)+0x04 );
- if ((strncmp(stamp, "ULTRAMID", 8) == 0)||(strncmp(stamp, "KARADOS", 7) == 0))
- break;
- }
- if (vector <= 0x7f) {
- if (um_hook)
- {
- _AX = TSR_APP_START;
- (*um_hook)();
- reset_um();
- }
- } else
- {
- um_hook = 0L;
- printf (" No synth found.\n");
- return(1);
- }
- return(0);
- case RIEN :
- default:
- printf (" No hard. Sorry.\n");
- return (1);
- }
- }
- #pragma warn .par
-
-
- void sbFmSound2(int car1, int car2)
- {
- if (um_hook)
- {
- switch (hardware)
- {
- case GUS:
- case SB:
- _AX = TSR_MIDI_OUT;
- _CX = car1;
- (*um_hook)();
- _AX = TSR_MIDI_OUT;
- _CX = car2;
- (*um_hook)();
- break;
- default:break;
- }
- }
- }
-
- void sbFmSound3(int car1, int car2, int car3)
- {
- if (um_hook)
- {
- switch (hardware)
- {
- case GUS:
- case SB:
- _AX = TSR_MIDI_OUT;
- _CX = car1;
- (*um_hook)();
- _AX = TSR_MIDI_OUT;
- _CX = car2;
- (*um_hook)();
- _AX = TSR_MIDI_OUT;
- _CX = car3;
- (*um_hook)();
- break;
- default:break;
- }
- }
- }
-
-